<?php
/**
 * @author jim
 * @date 2017/11/25
 *
 * 公司模块
 */

namespace app\admin\model;

use think\Model;

class BrJsCompanyModel extends Model
{
    protected $connection = 'JS_SERVE';
    protected $table = 'company';
    protected $resultSetType = 'collection';


    //查询单条记录
    public function findData($where,$column='*',$order=[]){
        if($order)
            $data = self::where($where)->field($column)->order($order)->find();
        else
            $data = self::where($where)->field($column)->find();
        $data ? $data = $data->toArray() : '';
        return $data;
    }

    //查询多条记录
    public function selectData($where,$column='*',$order=[]){
        if($order)
            $data = self::where($where)->field($column)->order($order)->select()->toArray();
        else
            $data = self::where($where)->field($column)->select()->toArray();
        return $data;
    }

    //更新记录
    public function editData($where,$data){
        $re = $this->save($data,$where);
        return $re;
    }

    //添加
    public function addData($data){
        $this->data($data);
        $this->isUpdate(false)->save();
        return $this->getLastInsID();
    }

    //删除数据
    public function delData($where){
        $this->destroy($where);
    }

    //筛选数据
    public function searchData($param,$page,$pernum,$order=['Id'=>'desc']){
        if($pernum)
            $data = self::where($param)->order($order)->limit($pernum)->page($page)->select()->toArray();
        else
            $data = self::where($param)->order($order)->select()->toArray();
        return $data;
    }

    //获取总数
    public function getTotalNum($param){
        return self::where($param)->count();
    }

    public function queryData($sql){
        $list = self::query($sql);
        return $list;
    }
}